{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/hpc2hdd/home/xzou428/Yuhao/HiGPT-tune-lightning\n"
     ]
    }
   ],
   "source": [
    "%cd /hpc2hdd/home/xzou428/Yuhao/HiGPT-tune-lightning/\n",
    "\n",
    "import torch\n",
    "\n",
    "state_dict = torch.load(\"checkpoints/higpt-stage1-llama3-MIX-WITH-HiGPT-epoch5-8192/lightning_logs/version_1/model_epoch=3-step=2528.ckpt\")[\"state_dict\"]\n",
    "\n",
    "new_sd = {\n",
    "    \"model.embed_tokens.weight\": state_dict[\"model.model.embed_tokens.weight\"],\n",
    "    \"model.graph_projector.weight\": state_dict[\"model.model.graph_projector.weight\"],\n",
    "    \"model.graph_projector.bias\": state_dict[\"model.model.graph_projector.bias\"]\n",
    "}\n",
    "\n",
    "torch.save(new_sd, \"checkpoints/freeze/llama3-8b-higpt-stage1-llama3-MIX-WITH-HiGPT-8192-version_1-epoch=3.bin\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "odict_keys(['model.model.embed_tokens.weight', 'model.model.layers.0.self_attn.q_proj.weight', 'model.model.layers.0.self_attn.k_proj.weight', 'model.model.layers.0.self_attn.v_proj.weight', 'model.model.layers.0.self_attn.o_proj.weight', 'model.model.layers.0.mlp.gate_proj.weight', 'model.model.layers.0.mlp.up_proj.weight', 'model.model.layers.0.mlp.down_proj.weight', 'model.model.layers.0.input_layernorm.weight', 'model.model.layers.0.post_attention_layernorm.weight', 'model.model.layers.1.self_attn.q_proj.weight', 'model.model.layers.1.self_attn.k_proj.weight', 'model.model.layers.1.self_attn.v_proj.weight', 'model.model.layers.1.self_attn.o_proj.weight', 'model.model.layers.1.mlp.gate_proj.weight', 'model.model.layers.1.mlp.up_proj.weight', 'model.model.layers.1.mlp.down_proj.weight', 'model.model.layers.1.input_layernorm.weight', 'model.model.layers.1.post_attention_layernorm.weight', 'model.model.layers.2.self_attn.q_proj.weight', 'model.model.layers.2.self_attn.k_proj.weight', 'model.model.layers.2.self_attn.v_proj.weight', 'model.model.layers.2.self_attn.o_proj.weight', 'model.model.layers.2.mlp.gate_proj.weight', 'model.model.layers.2.mlp.up_proj.weight', 'model.model.layers.2.mlp.down_proj.weight', 'model.model.layers.2.input_layernorm.weight', 'model.model.layers.2.post_attention_layernorm.weight', 'model.model.layers.3.self_attn.q_proj.weight', 'model.model.layers.3.self_attn.k_proj.weight', 'model.model.layers.3.self_attn.v_proj.weight', 'model.model.layers.3.self_attn.o_proj.weight', 'model.model.layers.3.mlp.gate_proj.weight', 'model.model.layers.3.mlp.up_proj.weight', 'model.model.layers.3.mlp.down_proj.weight', 'model.model.layers.3.input_layernorm.weight', 'model.model.layers.3.post_attention_layernorm.weight', 'model.model.layers.4.self_attn.q_proj.weight', 'model.model.layers.4.self_attn.k_proj.weight', 'model.model.layers.4.self_attn.v_proj.weight', 'model.model.layers.4.self_attn.o_proj.weight', 'model.model.layers.4.mlp.gate_proj.weight', 'model.model.layers.4.mlp.up_proj.weight', 'model.model.layers.4.mlp.down_proj.weight', 'model.model.layers.4.input_layernorm.weight', 'model.model.layers.4.post_attention_layernorm.weight', 'model.model.layers.5.self_attn.q_proj.weight', 'model.model.layers.5.self_attn.k_proj.weight', 'model.model.layers.5.self_attn.v_proj.weight', 'model.model.layers.5.self_attn.o_proj.weight', 'model.model.layers.5.mlp.gate_proj.weight', 'model.model.layers.5.mlp.up_proj.weight', 'model.model.layers.5.mlp.down_proj.weight', 'model.model.layers.5.input_layernorm.weight', 'model.model.layers.5.post_attention_layernorm.weight', 'model.model.layers.6.self_attn.q_proj.weight', 'model.model.layers.6.self_attn.k_proj.weight', 'model.model.layers.6.self_attn.v_proj.weight', 'model.model.layers.6.self_attn.o_proj.weight', 'model.model.layers.6.mlp.gate_proj.weight', 'model.model.layers.6.mlp.up_proj.weight', 'model.model.layers.6.mlp.down_proj.weight', 'model.model.layers.6.input_layernorm.weight', 'model.model.layers.6.post_attention_layernorm.weight', 'model.model.layers.7.self_attn.q_proj.weight', 'model.model.layers.7.self_attn.k_proj.weight', 'model.model.layers.7.self_attn.v_proj.weight', 'model.model.layers.7.self_attn.o_proj.weight', 'model.model.layers.7.mlp.gate_proj.weight', 'model.model.layers.7.mlp.up_proj.weight', 'model.model.layers.7.mlp.down_proj.weight', 'model.model.layers.7.input_layernorm.weight', 'model.model.layers.7.post_attention_layernorm.weight', 'model.model.layers.8.self_attn.q_proj.weight', 'model.model.layers.8.self_attn.k_proj.weight', 'model.model.layers.8.self_attn.v_proj.weight', 'model.model.layers.8.self_attn.o_proj.weight', 'model.model.layers.8.mlp.gate_proj.weight', 'model.model.layers.8.mlp.up_proj.weight', 'model.model.layers.8.mlp.down_proj.weight', 'model.model.layers.8.input_layernorm.weight', 'model.model.layers.8.post_attention_layernorm.weight', 'model.model.layers.9.self_attn.q_proj.weight', 'model.model.layers.9.self_attn.k_proj.weight', 'model.model.layers.9.self_attn.v_proj.weight', 'model.model.layers.9.self_attn.o_proj.weight', 'model.model.layers.9.mlp.gate_proj.weight', 'model.model.layers.9.mlp.up_proj.weight', 'model.model.layers.9.mlp.down_proj.weight', 'model.model.layers.9.input_layernorm.weight', 'model.model.layers.9.post_attention_layernorm.weight', 'model.model.layers.10.self_attn.q_proj.weight', 'model.model.layers.10.self_attn.k_proj.weight', 'model.model.layers.10.self_attn.v_proj.weight', 'model.model.layers.10.self_attn.o_proj.weight', 'model.model.layers.10.mlp.gate_proj.weight', 'model.model.layers.10.mlp.up_proj.weight', 'model.model.layers.10.mlp.down_proj.weight', 'model.model.layers.10.input_layernorm.weight', 'model.model.layers.10.post_attention_layernorm.weight', 'model.model.layers.11.self_attn.q_proj.weight', 'model.model.layers.11.self_attn.k_proj.weight', 'model.model.layers.11.self_attn.v_proj.weight', 'model.model.layers.11.self_attn.o_proj.weight', 'model.model.layers.11.mlp.gate_proj.weight', 'model.model.layers.11.mlp.up_proj.weight', 'model.model.layers.11.mlp.down_proj.weight', 'model.model.layers.11.input_layernorm.weight', 'model.model.layers.11.post_attention_layernorm.weight', 'model.model.layers.12.self_attn.q_proj.weight', 'model.model.layers.12.self_attn.k_proj.weight', 'model.model.layers.12.self_attn.v_proj.weight', 'model.model.layers.12.self_attn.o_proj.weight', 'model.model.layers.12.mlp.gate_proj.weight', 'model.model.layers.12.mlp.up_proj.weight', 'model.model.layers.12.mlp.down_proj.weight', 'model.model.layers.12.input_layernorm.weight', 'model.model.layers.12.post_attention_layernorm.weight', 'model.model.layers.13.self_attn.q_proj.weight', 'model.model.layers.13.self_attn.k_proj.weight', 'model.model.layers.13.self_attn.v_proj.weight', 'model.model.layers.13.self_attn.o_proj.weight', 'model.model.layers.13.mlp.gate_proj.weight', 'model.model.layers.13.mlp.up_proj.weight', 'model.model.layers.13.mlp.down_proj.weight', 'model.model.layers.13.input_layernorm.weight', 'model.model.layers.13.post_attention_layernorm.weight', 'model.model.layers.14.self_attn.q_proj.weight', 'model.model.layers.14.self_attn.k_proj.weight', 'model.model.layers.14.self_attn.v_proj.weight', 'model.model.layers.14.self_attn.o_proj.weight', 'model.model.layers.14.mlp.gate_proj.weight', 'model.model.layers.14.mlp.up_proj.weight', 'model.model.layers.14.mlp.down_proj.weight', 'model.model.layers.14.input_layernorm.weight', 'model.model.layers.14.post_attention_layernorm.weight', 'model.model.layers.15.self_attn.q_proj.weight', 'model.model.layers.15.self_attn.k_proj.weight', 'model.model.layers.15.self_attn.v_proj.weight', 'model.model.layers.15.self_attn.o_proj.weight', 'model.model.layers.15.mlp.gate_proj.weight', 'model.model.layers.15.mlp.up_proj.weight', 'model.model.layers.15.mlp.down_proj.weight', 'model.model.layers.15.input_layernorm.weight', 'model.model.layers.15.post_attention_layernorm.weight', 'model.model.layers.16.self_attn.q_proj.weight', 'model.model.layers.16.self_attn.k_proj.weight', 'model.model.layers.16.self_attn.v_proj.weight', 'model.model.layers.16.self_attn.o_proj.weight', 'model.model.layers.16.mlp.gate_proj.weight', 'model.model.layers.16.mlp.up_proj.weight', 'model.model.layers.16.mlp.down_proj.weight', 'model.model.layers.16.input_layernorm.weight', 'model.model.layers.16.post_attention_layernorm.weight', 'model.model.layers.17.self_attn.q_proj.weight', 'model.model.layers.17.self_attn.k_proj.weight', 'model.model.layers.17.self_attn.v_proj.weight', 'model.model.layers.17.self_attn.o_proj.weight', 'model.model.layers.17.mlp.gate_proj.weight', 'model.model.layers.17.mlp.up_proj.weight', 'model.model.layers.17.mlp.down_proj.weight', 'model.model.layers.17.input_layernorm.weight', 'model.model.layers.17.post_attention_layernorm.weight', 'model.model.layers.18.self_attn.q_proj.weight', 'model.model.layers.18.self_attn.k_proj.weight', 'model.model.layers.18.self_attn.v_proj.weight', 'model.model.layers.18.self_attn.o_proj.weight', 'model.model.layers.18.mlp.gate_proj.weight', 'model.model.layers.18.mlp.up_proj.weight', 'model.model.layers.18.mlp.down_proj.weight', 'model.model.layers.18.input_layernorm.weight', 'model.model.layers.18.post_attention_layernorm.weight', 'model.model.layers.19.self_attn.q_proj.weight', 'model.model.layers.19.self_attn.k_proj.weight', 'model.model.layers.19.self_attn.v_proj.weight', 'model.model.layers.19.self_attn.o_proj.weight', 'model.model.layers.19.mlp.gate_proj.weight', 'model.model.layers.19.mlp.up_proj.weight', 'model.model.layers.19.mlp.down_proj.weight', 'model.model.layers.19.input_layernorm.weight', 'model.model.layers.19.post_attention_layernorm.weight', 'model.model.layers.20.self_attn.q_proj.weight', 'model.model.layers.20.self_attn.k_proj.weight', 'model.model.layers.20.self_attn.v_proj.weight', 'model.model.layers.20.self_attn.o_proj.weight', 'model.model.layers.20.mlp.gate_proj.weight', 'model.model.layers.20.mlp.up_proj.weight', 'model.model.layers.20.mlp.down_proj.weight', 'model.model.layers.20.input_layernorm.weight', 'model.model.layers.20.post_attention_layernorm.weight', 'model.model.layers.21.self_attn.q_proj.weight', 'model.model.layers.21.self_attn.k_proj.weight', 'model.model.layers.21.self_attn.v_proj.weight', 'model.model.layers.21.self_attn.o_proj.weight', 'model.model.layers.21.mlp.gate_proj.weight', 'model.model.layers.21.mlp.up_proj.weight', 'model.model.layers.21.mlp.down_proj.weight', 'model.model.layers.21.input_layernorm.weight', 'model.model.layers.21.post_attention_layernorm.weight', 'model.model.layers.22.self_attn.q_proj.weight', 'model.model.layers.22.self_attn.k_proj.weight', 'model.model.layers.22.self_attn.v_proj.weight', 'model.model.layers.22.self_attn.o_proj.weight', 'model.model.layers.22.mlp.gate_proj.weight', 'model.model.layers.22.mlp.up_proj.weight', 'model.model.layers.22.mlp.down_proj.weight', 'model.model.layers.22.input_layernorm.weight', 'model.model.layers.22.post_attention_layernorm.weight', 'model.model.layers.23.self_attn.q_proj.weight', 'model.model.layers.23.self_attn.k_proj.weight', 'model.model.layers.23.self_attn.v_proj.weight', 'model.model.layers.23.self_attn.o_proj.weight', 'model.model.layers.23.mlp.gate_proj.weight', 'model.model.layers.23.mlp.up_proj.weight', 'model.model.layers.23.mlp.down_proj.weight', 'model.model.layers.23.input_layernorm.weight', 'model.model.layers.23.post_attention_layernorm.weight', 'model.model.layers.24.self_attn.q_proj.weight', 'model.model.layers.24.self_attn.k_proj.weight', 'model.model.layers.24.self_attn.v_proj.weight', 'model.model.layers.24.self_attn.o_proj.weight', 'model.model.layers.24.mlp.gate_proj.weight', 'model.model.layers.24.mlp.up_proj.weight', 'model.model.layers.24.mlp.down_proj.weight', 'model.model.layers.24.input_layernorm.weight', 'model.model.layers.24.post_attention_layernorm.weight', 'model.model.layers.25.self_attn.q_proj.weight', 'model.model.layers.25.self_attn.k_proj.weight', 'model.model.layers.25.self_attn.v_proj.weight', 'model.model.layers.25.self_attn.o_proj.weight', 'model.model.layers.25.mlp.gate_proj.weight', 'model.model.layers.25.mlp.up_proj.weight', 'model.model.layers.25.mlp.down_proj.weight', 'model.model.layers.25.input_layernorm.weight', 'model.model.layers.25.post_attention_layernorm.weight', 'model.model.layers.26.self_attn.q_proj.weight', 'model.model.layers.26.self_attn.k_proj.weight', 'model.model.layers.26.self_attn.v_proj.weight', 'model.model.layers.26.self_attn.o_proj.weight', 'model.model.layers.26.mlp.gate_proj.weight', 'model.model.layers.26.mlp.up_proj.weight', 'model.model.layers.26.mlp.down_proj.weight', 'model.model.layers.26.input_layernorm.weight', 'model.model.layers.26.post_attention_layernorm.weight', 'model.model.layers.27.self_attn.q_proj.weight', 'model.model.layers.27.self_attn.k_proj.weight', 'model.model.layers.27.self_attn.v_proj.weight', 'model.model.layers.27.self_attn.o_proj.weight', 'model.model.layers.27.mlp.gate_proj.weight', 'model.model.layers.27.mlp.up_proj.weight', 'model.model.layers.27.mlp.down_proj.weight', 'model.model.layers.27.input_layernorm.weight', 'model.model.layers.27.post_attention_layernorm.weight', 'model.model.layers.28.self_attn.q_proj.weight', 'model.model.layers.28.self_attn.k_proj.weight', 'model.model.layers.28.self_attn.v_proj.weight', 'model.model.layers.28.self_attn.o_proj.weight', 'model.model.layers.28.mlp.gate_proj.weight', 'model.model.layers.28.mlp.up_proj.weight', 'model.model.layers.28.mlp.down_proj.weight', 'model.model.layers.28.input_layernorm.weight', 'model.model.layers.28.post_attention_layernorm.weight', 'model.model.layers.29.self_attn.q_proj.weight', 'model.model.layers.29.self_attn.k_proj.weight', 'model.model.layers.29.self_attn.v_proj.weight', 'model.model.layers.29.self_attn.o_proj.weight', 'model.model.layers.29.mlp.gate_proj.weight', 'model.model.layers.29.mlp.up_proj.weight', 'model.model.layers.29.mlp.down_proj.weight', 'model.model.layers.29.input_layernorm.weight', 'model.model.layers.29.post_attention_layernorm.weight', 'model.model.layers.30.self_attn.q_proj.weight', 'model.model.layers.30.self_attn.k_proj.weight', 'model.model.layers.30.self_attn.v_proj.weight', 'model.model.layers.30.self_attn.o_proj.weight', 'model.model.layers.30.mlp.gate_proj.weight', 'model.model.layers.30.mlp.up_proj.weight', 'model.model.layers.30.mlp.down_proj.weight', 'model.model.layers.30.input_layernorm.weight', 'model.model.layers.30.post_attention_layernorm.weight', 'model.model.layers.31.self_attn.q_proj.weight', 'model.model.layers.31.self_attn.k_proj.weight', 'model.model.layers.31.self_attn.v_proj.weight', 'model.model.layers.31.self_attn.o_proj.weight', 'model.model.layers.31.mlp.gate_proj.weight', 'model.model.layers.31.mlp.up_proj.weight', 'model.model.layers.31.mlp.down_proj.weight', 'model.model.layers.31.input_layernorm.weight', 'model.model.layers.31.post_attention_layernorm.weight', 'model.model.norm.weight', 'model.model.graph_tower.kqv_lin.lin_gen.weight_generator.0.weight', 'model.model.graph_tower.kqv_lin.lin_gen.weight_generator.0.bias', 'model.model.graph_tower.kqv_lin.lin_gen.weight_generator.2.weight', 'model.model.graph_tower.kqv_lin.lin_gen.weight_generator.2.bias', 'model.model.graph_tower.kqv_lin.lin_gen.weight_generator.4.weight', 'model.model.graph_tower.kqv_lin.lin_gen.weight_generator.4.bias', 'model.model.graph_tower.kqv_lin.lin_gen.bias_generator.0.weight', 'model.model.graph_tower.kqv_lin.lin_gen.bias_generator.0.bias', 'model.model.graph_tower.kqv_lin.lin_gen.bias_generator.2.weight', 'model.model.graph_tower.kqv_lin.lin_gen.bias_generator.2.bias', 'model.model.graph_tower.kqv_lin.lin_gen.bias_generator.4.weight', 'model.model.graph_tower.kqv_lin.lin_gen.bias_generator.4.bias', 'model.model.graph_tower.out_lin.lin_gen.weight_generator.0.weight', 'model.model.graph_tower.out_lin.lin_gen.weight_generator.0.bias', 'model.model.graph_tower.out_lin.lin_gen.weight_generator.2.weight', 'model.model.graph_tower.out_lin.lin_gen.weight_generator.2.bias', 'model.model.graph_tower.out_lin.lin_gen.weight_generator.4.weight', 'model.model.graph_tower.out_lin.lin_gen.weight_generator.4.bias', 'model.model.graph_tower.out_lin.lin_gen.bias_generator.0.weight', 'model.model.graph_tower.out_lin.lin_gen.bias_generator.0.bias', 'model.model.graph_tower.out_lin.lin_gen.bias_generator.2.weight', 'model.model.graph_tower.out_lin.lin_gen.bias_generator.2.bias', 'model.model.graph_tower.out_lin.lin_gen.bias_generator.4.weight', 'model.model.graph_tower.out_lin.lin_gen.bias_generator.4.bias', 'model.model.graph_tower.k_rel.lin_gen.weight_generator.0.weight', 'model.model.graph_tower.k_rel.lin_gen.weight_generator.0.bias', 'model.model.graph_tower.k_rel.lin_gen.weight_generator.2.weight', 'model.model.graph_tower.k_rel.lin_gen.weight_generator.2.bias', 'model.model.graph_tower.k_rel.lin_gen.weight_generator.4.weight', 'model.model.graph_tower.k_rel.lin_gen.weight_generator.4.bias', 'model.model.graph_tower.k_rel.lin_gen.bias_generator.0.weight', 'model.model.graph_tower.k_rel.lin_gen.bias_generator.0.bias', 'model.model.graph_tower.k_rel.lin_gen.bias_generator.2.weight', 'model.model.graph_tower.k_rel.lin_gen.bias_generator.2.bias', 'model.model.graph_tower.k_rel.lin_gen.bias_generator.4.weight', 'model.model.graph_tower.k_rel.lin_gen.bias_generator.4.bias', 'model.model.graph_tower.v_rel.lin_gen.weight_generator.0.weight', 'model.model.graph_tower.v_rel.lin_gen.weight_generator.0.bias', 'model.model.graph_tower.v_rel.lin_gen.weight_generator.2.weight', 'model.model.graph_tower.v_rel.lin_gen.weight_generator.2.bias', 'model.model.graph_tower.v_rel.lin_gen.weight_generator.4.weight', 'model.model.graph_tower.v_rel.lin_gen.weight_generator.4.bias', 'model.model.graph_tower.v_rel.lin_gen.bias_generator.0.weight', 'model.model.graph_tower.v_rel.lin_gen.bias_generator.0.bias', 'model.model.graph_tower.v_rel.lin_gen.bias_generator.2.weight', 'model.model.graph_tower.v_rel.lin_gen.bias_generator.2.bias', 'model.model.graph_tower.v_rel.lin_gen.bias_generator.4.weight', 'model.model.graph_tower.v_rel.lin_gen.bias_generator.4.bias', 'model.model.graph_tower.skipTrans.weight', 'model.model.graph_tower.skipTrans.bias', 'model.model.graph_tower.p_relTrans.weight', 'model.model.graph_tower.p_relTrans.bias', 'model.model.graph_tower.norm.weight', 'model.model.graph_tower.norm.bias', 'model.model.graph_projector.weight', 'model.model.graph_projector.bias', 'model.lm_head.weight'])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "state_dict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_sd = {\n",
    "    \"model.embed_tokens.weight\": state_dict[\"model.model.embed_tokens.weight\"],\n",
    "    \"model.graph_projector.weight\": state_dict[\"model.model.graph_projector.weight\"],\n",
    "    \"model.graph_projector.bias\": state_dict[\"model.model.graph_projector.bias\"]\n",
    "}\n",
    "\n",
    "torch.save(new_sd, \"/hpc2hdd/home/xzou428/Yuhao/HiGPT-tune-lightning/checkpoints/freeze/higpt-metahgt-graphmatch-llama3-8b.bin\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.14 ('yuh')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "92619f85c62eb73280c07ca2268c8e47b90999a589aa097a1a08a504bd2fb2c6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
